Fix memory leak of pdo_odbc output parameter buffer#22734
Closed
iliaal wants to merge 1 commit into
Closed
Conversation
odbc_stmt_param_hook() allocates P->outbuf via emalloc for output and INPUT_OUTPUT parameters at PDO_PARAM_EVT_ALLOC, but nothing ever frees it. The buffer is handed to the driver with SQLBindParameter and outlives the bound-parameter struct, which PDO destroys mid-statement on execute with an array or on rebinding a position. Track the buffers on the statement and release them in the destructor, after SQLFreeHandle has dropped the bindings, so the leak is fixed without freeing a buffer the driver may still reference.
Contributor
Author
|
Superseded by #22735, which fixes this leak together with a related stale-binding out-of-bounds read in the same parameter-binding code. Closing in favour of that one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
odbc_stmt_param_hook()emallocsP->outbuffor output and INPUT_OUTPUT parameters atPDO_PARAM_EVT_ALLOC, hands it to the driver withSQLBindParameter, and never frees it. The buffer outlives the bound-parameter struct (PDO destroys that mid-statement onexecute($array)or when a position is rebound), so it cannot be freed at parameter-free time without leaving the ODBC statement pointing at freed memory. Track the allocated buffers on the statement and free them in the destructor, afterSQLFreeHandlehas dropped the bindings.Reproducer, leaks under a debug or ASAN build: